package com.ruoyi.web.controller.biz;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.biz.BmMember;
import com.ruoyi.system.service.biz.IBmMemberService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员Controller
 * 
 * @author xiangzhipeng
 * @date 2022-11-25
 */
@Controller
@RequestMapping("/biz/member")
public class BmMemberController extends BaseController
{
    private String prefix = "biz/member";

    @Autowired
    private IBmMemberService bmMemberService;

    @RequiresPermissions("biz:member:view")
    @GetMapping()
    public String member()
    {
        return prefix + "/member";
    }

    /**
     * 查询会员列表
     */
    @RequiresPermissions("biz:member:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BmMember bmMember)
    {
        startPage();
        List<BmMember> list = bmMemberService.selectBmMemberList(bmMember);
        return getDataTable(list);
    }

    /**
     * 导出会员列表
     */
    @RequiresPermissions("biz:member:export")
    @Log(title = "会员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BmMember bmMember)
    {
        List<BmMember> list = bmMemberService.selectBmMemberList(bmMember);
        ExcelUtil<BmMember> util = new ExcelUtil<BmMember>(BmMember.class);
        return util.exportExcel(list, "会员数据");
    }

    /**
     * 新增会员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会员
     */
    @RequiresPermissions("biz:member:add")
    @Log(title = "会员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BmMember bmMember)
    {
        return toAjax(bmMemberService.insertBmMember(bmMember));
    }

    /**
     * 修改会员
     */
    @RequiresPermissions("biz:member:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BmMember bmMember = bmMemberService.selectBmMemberById(id);
        mmap.put("bmMember", bmMember);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员
     */
    @RequiresPermissions("biz:member:edit")
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BmMember bmMember)
    {
        return toAjax(bmMemberService.updateBmMember(bmMember));
    }

    /**
     * 删除会员
     */
    @RequiresPermissions("biz:member:remove")
    @Log(title = "会员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bmMemberService.deleteBmMemberByIds(ids));
    }
}
